//
//  PATradeInfo.m
//  PAMobileWallet
//
//  Created by Gavin Zhang on 7/14/13.
//  Copyright (c) 2013 平安付. All rights reserved.
//

#import "PATradeInfo.h"

@implementation PATradeInfo
@synthesize mediaUrl            = _mediaUrl;
@synthesize tradeAmount         = _tradeAmount;
@synthesize tradeCreatedDate    = _tradeCreatedDate;
@synthesize tradeId             = _tradeId;
@synthesize tradeDirection      = _tradeDirection;
@synthesize tradeStatus         = _tradeStatus;
@synthesize tradeType           = _tradeType;
@synthesize updateDate          = _updateDate;

- (id)initWithDic:(NSDictionary *)dic
{
    self = [super init];
    if (self) {
        if ([dic objectForKey:@"mediaUrl"]) self.mediaUrl = [dic objectForKey:@"mediaUrl"];
        if ([dic objectForKey:@"tradeAmount"]) self.tradeAmount = [[dic objectForKey:@"tradeAmount"] doubleValue];
        if ([dic objectForKey:@"tradeCreatedDate"]) self.tradeCreatedDate = [dic objectForKey:@"tradeCreatedDate"];
        id tradeId = [dic objectForKey:@"tradeId"];
        if (tradeId) {
            /*
             *  当前后台 定义 的 订单号 为 数据类型
             *  新后台 定义 的 订单号 数据类型 尚未可知
             */
            
            if ([tradeId isKindOfClass:[NSNumber class]]) {
                self.tradeId = [NSString stringWithFormat:@"%d",[(NSNumber *)tradeId integerValue]];
            }else{
                self.tradeId = tradeId;
            }
        }
        if ([dic objectForKey:@"tradeDirection"]) self.tradeDirection = [[dic objectForKey:@"tradeDirection"] integerValue];
        if ([dic objectForKey:@"tradeStatus"]) self.tradeStatus = [[dic objectForKey:@"tradeStatus"] integerValue];
        if ([dic objectForKey:@"tradeType"]) self.tradeType = [[dic objectForKey:@"tradeType"] integerValue];
        if ([dic objectForKey:@"updateDate"]) self.updateDate = [dic objectForKey:@"updateDate"];
    }
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{
    [aCoder encodeObject:_mediaUrl forKey:@"mediaUrl"];
    [aCoder encodeFloat:_tradeAmount forKey:@"tradeAmount"];
    [aCoder encodeObject:_tradeCreatedDate forKey:@"tradeCreatedDate"];
    [aCoder encodeObject:_tradeId forKey:@"tradeId"];
    [aCoder encodeInteger:_tradeDirection forKey:@"lastTradeDirection"];
    [aCoder encodeInteger:_tradeStatus forKey:@"tradeStatus"];
    [aCoder encodeInteger:_tradeType forKey:@"tradeType"];
    [aCoder encodeObject:_updateDate forKey:@"updateDate"];
}

- (id)initWithCoder:(NSCoder *)aDecoder{
    self = [super init];
    if (self) {
        _mediaUrl = [aDecoder decodeObjectForKey:@"mediaUrl"];
        _tradeAmount = [aDecoder decodeFloatForKey:@"tradeAmount"];
        _tradeCreatedDate = [aDecoder decodeObjectForKey:@"tradeCreatedDate"];
        _tradeId = [aDecoder decodeObjectForKey:@"tradeId"];
        _tradeDirection = [aDecoder decodeIntegerForKey:@"lastTradeDirection"];
        _tradeStatus = [aDecoder decodeIntegerForKey:@"tradeStatus"];
        _tradeType = [aDecoder decodeIntegerForKey:@"tradeType"];
        _updateDate = [aDecoder decodeObjectForKey:@"updateDate"];
    }
    return self;
}
@end
